import axios from 'axios'
import {Toast} from 'vant'
import store from '../store';
import router from '../router'
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
const service = axios.create({
    baseURL: process.env.NODE_ENV === 'development' ? '/raw' : 'https://dapp-api.stcdao.vip/',
    //baseURL: 'https://dapp-api.stcdao.vip/',
    withCredentials: true,
    timeout: 50000
})

/** 请求拦截器 */
service.interceptors.request.use(
    config => {
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

/** 响应拦截器 */
service.interceptors.response.use(
    response => {
        if (response.data.code != undefined) {
            return response.data
        } else {
            Toast.fail('请求失败')
            return Promise.reject(response.data.msg || 'error')
        }
    }
)


export default service